package com.wty.cmims.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wty.cmims.pojo.Code;
import com.wty.cmims.pojo.Medication;
import com.wty.cmims.pojo.ResponseResult;
import com.wty.cmims.service.MedicationService;
import com.wty.cmims.mapper.MedicationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
* @author wty
* @description 针对表【medication】的数据库操作Service实现
* @createDate 2024-10-31 22:00:42
*/
@Service
public class MedicationServiceImpl extends ServiceImpl<MedicationMapper, Medication>
    implements MedicationService{
    @Autowired
    private MedicationMapper medicationMapper;
    @Override
    public ResponseResult<Map<String, Object>> medicationFind(Map<String,Object> paramsMap) {
        // 分页
        ResponseResult<Map<String, Object>> responseResult = new ResponseResult<>();
        Integer pageSize = (Integer) paramsMap.get("pageSize");
        paramsMap.put("start", ((Integer) paramsMap.get("currentPage") - 1) * pageSize);
        responseResult.setPageSize(pageSize);

        List<Map<String, Object>> medications = medicationMapper.findMedications(paramsMap);
        Integer total = medicationMapper.findMedicationsNum(paramsMap);
        if (medications != null) {
            responseResult.setCode(Code.SUCCESS);
            responseResult.setMessage("查询药品信息成功");
            responseResult.setDatas(medications);
            responseResult.setTotal(total);
            responseResult.setCurrentPage((Integer) paramsMap.get("currentPage"));
        } else {
            responseResult.setCode(Code.ERROR);
            responseResult.setMessage("查询药品信息失败");
        }
        return responseResult;
    }
}




